﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace DataAccess
{
    /// <summary>
    /// 数据访问类:TB_HSYXRK_BASE
    /// </summary>
    public partial class TB_HSYXRK_BASE
    {
        public TB_HSYXRK_BASE()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(decimal NID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TB_HSYXRK_BASE");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static Model.TB_HSYXRK_BASE Add(Model.TB_HSYXRK_BASE model)
        {
            model.NID = CommonExecute.GetID(model.GetType().Name);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TB_HSYXRK_BASE(");
            strSql.Append("NID,CSQDH,CSQMC,SQMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,LSH,CREATE_USER,CREATE_DATE)");
            strSql.Append(" values (");
            strSql.Append(":NID,:CSQDH,:CSQMC,:SQMJ,:NYPTS,:NYPS,:DTJSRQ,:DTRKRQ,:CHSDW,:LSH,:CREATE_USER,:CREATE_DATE)");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,10),
					new OracleParameter(":CSQDH", OracleType.NVarChar),
					new OracleParameter(":CSQMC", OracleType.VarChar,100),
					new OracleParameter(":SQMJ", OracleType.Number,10),
					new OracleParameter(":NYPTS", OracleType.Number,1),
					new OracleParameter(":NYPS", OracleType.Number,10),
					new OracleParameter(":DTJSRQ", OracleType.DateTime),
					new OracleParameter(":DTRKRQ", OracleType.DateTime),
					new OracleParameter(":CHSDW", OracleType.NVarChar),
					new OracleParameter(":LSH", OracleType.Number,10),
					new OracleParameter(":CREATE_USER", OracleType.VarChar,50),
					new OracleParameter(":CREATE_DATE", OracleType.DateTime)};
            parameters[0].Value = model.NID;
            parameters[1].Value = model.CSQDH;
            parameters[2].Value = model.CSQMC;
            parameters[3].Value = model.SQMJ;
            parameters[4].Value = model.NYPTS;
            parameters[5].Value = model.NYPS;
            parameters[6].Value = model.DTJSRQ;
            parameters[7].Value = model.DTRKRQ;
            parameters[8].Value = model.CHSDW;
            parameters[9].Value = model.LSH;
            parameters[10].Value = model.CREATE_USER;
            parameters[11].Value = model.CREATE_DATE;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool Update(Model.TB_HSYXRK_BASE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update TB_HSYXRK_BASE set ");
            strSql.Append("CSQDH=:CSQDH,");
            strSql.Append("CSQMC=:CSQMC,");
            strSql.Append("SQMJ=:SQMJ,");
            strSql.Append("NYPTS=:NYPTS,");
            strSql.Append("NYPS=:NYPS,");
            strSql.Append("DTJSRQ=:DTJSRQ,");
            strSql.Append("DTRKRQ=:DTRKRQ,");
            strSql.Append("CHSDW=:CHSDW,");
            strSql.Append("LSH=:LSH,");
            strSql.Append("CREATE_USER=:CREATE_USER,");
            strSql.Append("CREATE_DATE=:CREATE_DATE");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":CSQDH", OracleType.NVarChar),
					new OracleParameter(":CSQMC", OracleType.VarChar,100),
					new OracleParameter(":SQMJ", OracleType.Number,10),
					new OracleParameter(":NYPTS", OracleType.Number,1),
					new OracleParameter(":NYPS", OracleType.Number,10),
					new OracleParameter(":DTJSRQ", OracleType.DateTime),
					new OracleParameter(":DTRKRQ", OracleType.DateTime),
					new OracleParameter(":CHSDW", OracleType.NVarChar),
					new OracleParameter(":LSH", OracleType.Number,10),
					new OracleParameter(":CREATE_USER", OracleType.VarChar,50),
					new OracleParameter(":CREATE_DATE", OracleType.DateTime),
					new OracleParameter(":NID", OracleType.Number,10)};
            parameters[0].Value = model.CSQDH;
            parameters[1].Value = model.CSQMC;
            parameters[2].Value = model.SQMJ;
            parameters[3].Value = model.NYPTS;
            parameters[4].Value = model.NYPS;
            parameters[5].Value = model.DTJSRQ;
            parameters[6].Value = model.DTRKRQ;
            parameters[7].Value = model.CHSDW;
            parameters[8].Value = model.LSH;
            parameters[9].Value = model.CREATE_USER;
            parameters[10].Value = model.CREATE_DATE;
            parameters[11].Value = model.NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static bool Delete(decimal NID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_HSYXRK_BASE ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public static bool DeleteList(string NIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TB_HSYXRK_BASE ");
            strSql.Append(" where NID in (" + NIDlist + ")  ");
            int rows = DbHelperOra.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Model.TB_HSYXRK_BASE GetModel(decimal NID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CSQDH,CSQMC,SQMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,LSH,CREATE_USER,CREATE_DATE from TB_HSYXRK_BASE ");
            strSql.Append(" where NID=:NID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NID", OracleType.Number,22)};
            parameters[0].Value = NID;

            Model.TB_HSYXRK_BASE model = new Model.TB_HSYXRK_BASE();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CSQDH"] != null && ds.Tables[0].Rows[0]["CSQDH"].ToString() != "")
                {
                    model.CSQDH = ds.Tables[0].Rows[0]["CSQDH"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CSQMC"] != null && ds.Tables[0].Rows[0]["CSQMC"].ToString() != "")
                {
                    model.CSQMC = ds.Tables[0].Rows[0]["CSQMC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SQMJ"] != null && ds.Tables[0].Rows[0]["SQMJ"].ToString() != "")
                {
                    model.SQMJ = decimal.Parse(ds.Tables[0].Rows[0]["SQMJ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPTS"] != null && ds.Tables[0].Rows[0]["NYPTS"].ToString() != "")
                {
                    model.NYPTS = decimal.Parse(ds.Tables[0].Rows[0]["NYPTS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPS"] != null && ds.Tables[0].Rows[0]["NYPS"].ToString() != "")
                {
                    model.NYPS = decimal.Parse(ds.Tables[0].Rows[0]["NYPS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTJSRQ"] != null && ds.Tables[0].Rows[0]["DTJSRQ"].ToString() != "")
                {
                    model.DTJSRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTJSRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTRKRQ"] != null && ds.Tables[0].Rows[0]["DTRKRQ"].ToString() != "")
                {
                    model.DTRKRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTRKRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CHSDW"] != null && ds.Tables[0].Rows[0]["CHSDW"].ToString() != "")
                {
                    model.CHSDW = ds.Tables[0].Rows[0]["CHSDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LSH"] != null && ds.Tables[0].Rows[0]["LSH"].ToString() != "")
                {
                    model.LSH = decimal.Parse(ds.Tables[0].Rows[0]["LSH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CREATE_USER"] != null && ds.Tables[0].Rows[0]["CREATE_USER"].ToString() != "")
                {
                    model.CREATE_USER = ds.Tables[0].Rows[0]["CREATE_USER"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_DATE"] != null && ds.Tables[0].Rows[0]["CREATE_DATE"].ToString() != "")
                {
                    model.CREATE_DATE = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Model.TB_HSYXRK_BASE GetModel(string CSQDH)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CSQDH,CSQMC,SQMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,LSH,CREATE_USER,CREATE_DATE from TB_HSYXRK_BASE ");
            strSql.Append(" where CSQDH=:CSQDH ");
            OracleParameter[] parameters = {
					new OracleParameter(":CSQDH", OracleType.NVarChar)};
            parameters[0].Value = CSQDH;

            Model.TB_HSYXRK_BASE model = new Model.TB_HSYXRK_BASE();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["NID"] != null && ds.Tables[0].Rows[0]["NID"].ToString() != "")
                {
                    model.NID = decimal.Parse(ds.Tables[0].Rows[0]["NID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CSQDH"] != null && ds.Tables[0].Rows[0]["CSQDH"].ToString() != "")
                {
                    model.CSQDH = ds.Tables[0].Rows[0]["CSQDH"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CSQMC"] != null && ds.Tables[0].Rows[0]["CSQMC"].ToString() != "")
                {
                    model.CSQMC = ds.Tables[0].Rows[0]["CSQMC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SQMJ"] != null && ds.Tables[0].Rows[0]["SQMJ"].ToString() != "")
                {
                    model.SQMJ = decimal.Parse(ds.Tables[0].Rows[0]["SQMJ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPTS"] != null && ds.Tables[0].Rows[0]["NYPTS"].ToString() != "")
                {
                    model.NYPTS = decimal.Parse(ds.Tables[0].Rows[0]["NYPTS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NYPS"] != null && ds.Tables[0].Rows[0]["NYPS"].ToString() != "")
                {
                    model.NYPS = decimal.Parse(ds.Tables[0].Rows[0]["NYPS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTJSRQ"] != null && ds.Tables[0].Rows[0]["DTJSRQ"].ToString() != "")
                {
                    model.DTJSRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTJSRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DTRKRQ"] != null && ds.Tables[0].Rows[0]["DTRKRQ"].ToString() != "")
                {
                    model.DTRKRQ = DateTime.Parse(ds.Tables[0].Rows[0]["DTRKRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CHSDW"] != null && ds.Tables[0].Rows[0]["CHSDW"].ToString() != "")
                {
                    model.CHSDW = ds.Tables[0].Rows[0]["CHSDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LSH"] != null && ds.Tables[0].Rows[0]["LSH"].ToString() != "")
                {
                    model.LSH = decimal.Parse(ds.Tables[0].Rows[0]["LSH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CREATE_USER"] != null && ds.Tables[0].Rows[0]["CREATE_USER"].ToString() != "")
                {
                    model.CREATE_USER = ds.Tables[0].Rows[0]["CREATE_USER"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_DATE"] != null && ds.Tables[0].Rows[0]["CREATE_DATE"].ToString() != "")
                {
                    model.CREATE_DATE = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CSQDH,CSQMC,SQMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,LSH,CREATE_USER,CREATE_DATE ");
            strSql.Append(" FROM TB_HSYXRK_BASE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataTable GetList(string strWhere, int startRecord, int maxRecords)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NID,CSQDH,CSQMC,SQMJ,NYPTS,NYPS,DTJSRQ,DTRKRQ,CHSDW,LSH,CREATE_USER,CREATE_DATE,CnickName ");
            strSql.Append(" FROM HSYXRK_BASE_view ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }

            return DbHelperOra.Query(strSql.ToString(), startRecord, maxRecords);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataTable GetSumHD(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  nvl(sum(FSJL),0) as FSJL,nvl(sum(NSMPS),0) as NSMPS  from HSYXRK_BASE_view a,TB_HSYXRK_HD b where a.NID=b.Nsqid ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString()).Tables[0];
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataTable GetSumBASE(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select nvl(sum(SQMJ),0) as SQMJ ");
            strSql.Append(" FROM HSYXRK_BASE_view ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString()).Tables[0];
        }

        /// <summary>
        /// 获取记录数
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public static int GetCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) num ");
            strSql.Append(" FROM TB_HSYXRK_BASE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperOra.GetSingle(strSql.ToString());
            return int.Parse(obj.ToString());
        }  
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public static DataSet GetHDList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from HSYXRK_BASE_HD_List_view ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }
        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "TB_HSYXRK_BASE";
            parameters[1].Value = "CSQDH";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/


        #endregion  Method
    }
}

